package com.hualan.web.fore;
import com.hualan.pojo.Huifudayi;
import com.hualan.service.service.service.ProblemService;
import com.hualan.service.service.service.ProblemServiceImpl;
import com.alibaba.fastjson.JSON;
import com.hualan.service.service.service.HuifudayiService;
import com.hualan.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;@RestController
@RequestMapping("/huifudayi")
public class HuifudayiController {
    @Autowired
    private HuifudayiService huifudayiService;
    @Autowired
    private ProblemService problemService;
    @RequestMapping("/listById")
    public ResultEntity listById(Integer pid) {
        return ResultEntity.ok(huifudayiService.listById(pid));
    }
    @RequestMapping("/add")
    public ResultEntity add(@RequestBody Huifudayi huifudayi) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        huifudayi.setTime(dateFormat.format(new Date()));
        return ResultEntity.ok(huifudayiService.add(huifudayi));
    }
    @RequestMapping("/listMyAnswer")//�ҵĻش���
    public ResultEntity listMyAnswer(Integer uid) {
        List<Integer> list = problemService.listIdByUid(uid);
        if(list.isEmpty()) {
            return ResultEntity.ok(false);
        }
        return ResultEntity.ok(JSON.toJSON(huifudayiService.listByPids(list)));
    }
    @RequestMapping("/listToMe")//�ҵ�֪ͨ����
    public ResultEntity listToMe(Integer uid) {
        List<Huifudayi> list = huifudayiService.listToMe(uid);
        if(list.isEmpty()) {
            return ResultEntity.ok(false);
        }
        return ResultEntity.ok(JSON.toJSON(list));
    }
}
